/**
 * 获取背景墙照片
 */

const fs = require('fs')
const path = require('path')
const utils = require('../common/utils')

const photowallPath = path.join(__dirname, '../public/img/photowall/comic/')

function getPhoto(limit = 10) {
  return new Promise((resolve, reject) => {
    fs.readdir(photowallPath, (err, suc) => {
      if (err) {
        reject(err)
      } else {
        let result = random(suc, limit)
        resolve(result)
      }
    })
  })
}


function random(smallArr, limit) {
  let result = []
  for (let i = 0; i < limit; i++) {
    let ran = utils.randomNum(0, smallArr.length - 1)
    result.push('http://127.0.0.1:5000/public/img/photowall/comic/' + smallArr[ran])
    smallArr.splice(ran, 1)
  }
  return result
}



module.exports = {
  getPhoto
}